package cn.da.shuai.cool.finance.controller;

import cn.da.shuai.cool.finance.model.CoolBudgetControl;
import cn.da.shuai.cool.finance.service.ICoolBudgetControlService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预算管理控制接口API类
 */
@RestController
@RequestMapping("/api/finance/budget-control")
@Tag(name = "预算管理控制接口")
public class CoolBudgetControlController {

    @Autowired
    private ICoolBudgetControlService budgetControlService;

    @GetMapping("/active")
    @Operation(summary = "获取活跃预算管理控制列表")
    public List<CoolBudgetControl> getActiveBudgetControls(
            @Parameter(description = "部门ID", required = true) @RequestParam Long departmentId,
            @Parameter(description = "预算类别", required = false) @RequestParam(required = false) String category,
            @Parameter(description = "财政年度", required = true) @RequestParam Integer fiscalYear,
            @Parameter(description = "财政月份", required = true) @RequestParam Integer fiscalMonth) {
        return budgetControlService.getActiveBudgetControls(departmentId, category, fiscalYear, fiscalMonth);
    }

    @PostMapping("/apply")
    @Operation(summary = "申请预算管理控制")
    public void applyBudgetControl(@RequestBody CoolBudgetControl budgetControl) {
        budgetControlService.applyBudgetControl(budgetControl);
    }

    @DeleteMapping("/deactivate")
    @Operation(summary = "停用预算管理控制")
    public void deactivateBudgetControl(
            @Parameter(description = "预算管理控制ID", required = true) @RequestParam Long budgetControlId) {
        budgetControlService.deactivateBudgetControl(budgetControlId);
    }
}